package com.lagou.web.controller;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping
public class TestController {

    @Reference
    private HelloService helloService;

    final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(200, 500, 100L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100000));

    @GetMapping("/test")
    public void test() {
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("任务启动 start ------");

                //执行methodA
                threadPoolExecutor.execute(() -> {
                    helloService.methodA();
                });

                //执行methodB
                threadPoolExecutor.execute(() -> {
                    helloService.methodB();
                });

                //执行methodC
                threadPoolExecutor.execute(() -> {
                    helloService.methodC();
                });

            }
        }, 0, 100);

    }
}
